package com.sinopec.basemodule.common;

import com.orhanobut.hawk.Hawk;
import com.sinopec.basemodule.AppConstants;
import com.sinopec.basemodule.model.login_model.UserInfo;
import com.sinopec.basemodule.model.mine_model.MineInfoModel;

public class UserManager {

    private UserInfo user;

    public UserManager() {
        checkUser();
    }

    private void checkUser() {
        if (user == null) {
            user = Hawk.get(AppConstants.HAWK_USER);
        }
    }

    public UserInfo getUser() {
        checkUser();
        return user;
    }

    public void setUser(UserInfo user) {
        Hawk.delete(AppConstants.HAWK_USER);
        Hawk.put(AppConstants.HAWK_USER, user);
        this.user = user;
    }

    public String getUserName() {
        return user.getUserName();
    }

    public String getPhone() {
        return getUser().getUserAccount();
    }

    public String getWarehouseName() {
        return user.getStockWarehouseName();
    }

    public String getWarehouseId() {
        return user.getStockWarehouseId();
    }

    public void setWarehouseId(String warehouseId){
        user.setStockWarehouseId(warehouseId);
        setUser(user);
    }

    public void updateUserInfo(MineInfoModel mineInfoModel) {
        Hawk.put(AppConstants.HAWK_USER, user);
    }
}
